package util;

import java.io.InputStream;
import java.sql.DriverManager;
import java.util.Properties;
import java.util.ResourceBundle;

import javax.swing.JOptionPane;

/**
 * This class uses to get database connection.
 * 
 * @author joanie
 */
public class Connection {

        private static ResourceBundle dbResource = ResourceBundle.getBundle("db");
        
	public static java.sql.Connection getConnection() {
		// load the driver and establish a connection.
		try {
			String jdbcDriver = dbResource.getString(Constants.JDBD_DRIVER);
			String jdbcUrl = dbResource.getString(Constants.JDBD_URL);
			String jdbcUser = dbResource.getString(Constants.JDBD_USER);
			String jdbcPassword = dbResource.getString(Constants.JDBD_PASS);

			Class.forName(jdbcDriver);
			return (java.sql.Connection) DriverManager.getConnection(jdbcUrl,jdbcUser,jdbcPassword);
			
		} catch (Exception ex) {
			//System.out.println(ex.getMessage());
			JOptionPane.showMessageDialog(null, ex.getMessage());
		}
		return null;
	}	
}
